package com.tensquare.gateway.controller;

import com.tensquare.entity.Result;
import com.tensquare.entity.StatusCode;
import com.tensquare.gateway.service.RsaService;
import com.tensquare.rsa.RsaKeys;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping(value = "enc")
public class RsaEncryptController {

    @Autowired
    private RsaService rsaService;

    @RequestMapping(value = "{data}")
    public Result getEncData(@PathVariable String data) throws Exception {
        log.info("data->{}",data);
        return new Result(true, "加密成功", StatusCode.OK, rsaService.RSAEncryptDataPEM(data, RsaKeys.getServerPubKey()));
    }
}
